<?php
function GetFileInfo($aFileName,$aResourceName) {
  $handle = fopen($aFileName,'rb');
  
  if (!$handle) return False;
  
  $Header = fread($handle,64);
  
  if (substr($Header,0,2) != 'MZ') return False;
  
  $PEOffset = unpack("V",substr($Header,60,4));
  
  if ($PEOffset[1] < 64) return False;
  
  fseek($handle,$PEOffset[1],SEEK_SET);
  
  $Header = fread ($handle,24);
  
  if (substr($Header,0,2) != 'PE') return False;
  
  $Machine = unpack("v",substr($Header,4,2));
  
  if ($Machine[1] != 332) return False;
  
  $NoSections = unpack("v",substr($Header,6,2));
  $OptHdrSize = unpack("v",substr($Header,20,2));
  
  fseek($handle,$OptHdrSize[1],SEEK_CUR);
  
  $ResFound = False;
  
  for ($i = 0;$i < $NoSections[1];$i++) {
    $SecHdr = fread($handle,40);
    
    if (substr($SecHdr,0,5) == '.rsrc') {         //resource section
      $ResFound = True;
      break;
    }
  }

  if (!$ResFound) return False;
  
  $InfoVirt = unpack("V",substr($SecHdr,12,4));
  $InfoSize = unpack("V",substr($SecHdr,16,4));
  $InfoOff = unpack("V",substr($SecHdr,20,4));
  
  fseek($handle,$InfoOff[1],SEEK_SET);
  
  $Info = fread($handle,$InfoSize[1]);
  $NumDirs = unpack("v",substr($Info,14,2));
  $InfoFound = False;
  
  for ($i = 0;$i < $NumDirs[1];$i++) {
    $Type = unpack("V",substr($Info,($i*8)+16,4));
    if($Type[1] == 16) {                          //FILEINFO resource
      $InfoFound = True;
      $SubOff = unpack("V",substr($Info,($i*8)+20,4));
      break;
    }
  }

  if (!$InfoFound) return False;

  $encodedKey = implode("\x00",str_split($aResourceName));
  $StartOfSeekingKey = strpos($Info, $encodedKey);
  
  if ($StartOfSeekingKey !== false) {
    $ulgyRemainderOfData = substr($Info, $StartOfSeekingKey);

    $ArrayOfValues = explode("\x00\x00\x00", $ulgyRemainderOfData);
    return trim(str_replace("\x00","",$ArrayOfValues[1])); // the key your are seeking is 0, where the value is one
  }

  return false;
}
// sempre verifica quem é lower
//                     -1    0    1
echo("2.5.1 > 2.5.2? " . version_compare("2.5.1",  "2.5.2", ">") . "<br>"); // expect -1
echo("2.5.2 > 2.5.2? " . version_compare("2.5.2",  "2.5.2", ">") . "<br>"); // expect 0
echo("2.5.5 > 2.5.2? " . version_compare("2.5.5",  "2.5.2", ">") . "<br>"); // expect 1
echo("2.5.11 > 21.5.2? " . version_compare("2.5.11", "21.5.2", ">") . "<br>"); // expect 1
echo("1.0.0.0 > 1.0.0? " . version_compare("1.0.0.0", "1.0.0", ">") . "<br>");

echo(md5_file("D:\\GSCSetup.exe"));

//echo("FileDescription = ". GetFileInfo("D:\\GSCSetup.exe", 'FileDescription') . "<br>");
//echo("ProductName = " . GetFileInfo("D:\\GSCSetup.exe", 'ProductName') . "<br>");
//echo("ProductVersion = " . GetFileInfo("/home/weboportun/downloads/gsc/GSCSetup.exe", 'ProductVersion') . "<br>");
//echo("Copyright = " . GetFileInfo("D:\\GSCSetup.exe", 'Copyright') . "<br>");
?> 